package com.hundsun.yr.universal.p2p.ui.activity;

import android.os.Bundle;
import android.view.View;

import com.hundsun.mobile.zwgt.R;
import com.hundsun.yr.universal.library.eventbus.EventCenter;
import com.hundsun.yr.universal.library.netstatus.NetUtils;
import com.hundsun.yr.universal.p2p.bean.UserInfo;
import com.hundsun.yr.universal.p2p.config.Constants;
import com.hundsun.yr.universal.p2p.config.TaskConstants;
import com.hundsun.yr.universal.p2p.presenter.base.RequestPresenter;
import com.hundsun.yr.universal.p2p.presenter.impl.InitializePresenterImpl;
import com.hundsun.yr.universal.p2p.ui.activity.base.BaseActivity;
import com.hundsun.yr.universal.p2p.utils.BaseRequestTool2;
import com.hundsun.yr.universal.p2p.utils.CommTool;
import com.hundsun.yr.universal.p2p.view.base.InitializeView;
import com.hundsun.yr.universal.p2p.widget.ItemView;

import org.json.JSONException;
import org.json.JSONObject;

/**
 * Created by xx on 2017/6/12.
 */
public class PasswordMangerActivity extends BaseActivity implements InitializeView,View.OnClickListener{
    private ItemView itemv_update_password;
    private ItemView itemv_resetting_password;
    private RequestPresenter mPresenter;
    private String zwgt_data;
    private String phone;

    @Override
    protected boolean isApplyKitKatTranslucency() {
        return true;
    }

    @Override
    protected int getContentViewLayoutID() {
        return R.layout.act_passwordmanager;
    }

    @Override
    protected void initViewsAndEvents() {
        findView();
        toolbar_title.setText(getString(R.string.manager_login_password));
        phone = sharedPreferences.getShareProf(UserInfo.MOBILE);
        itemv_update_password.setOnClickListener(this);
        itemv_resetting_password.setOnClickListener(this);
    }

    protected void initImmersionBar() {
        super.initImmersionBar();
        mImmersionBar.titleBar(R.id.common_toolbar).init();
    }

    @Override
    protected void getBundleExtras(Bundle extras) {

    }

    @Override
    protected void onEveComming(EventCenter eventCenter) {

    }

    @Override
    protected boolean isBindEventBusHere() {
        return false;
    }

    @Override
    protected View getLoadingTargetView() {
        return null;
    }

    @Override
    protected void onNetworkConnected(NetUtils.NetType type) {

    }

    @Override
    protected void onNetworkDisConnected() {

    }

    @Override
    protected boolean isApplyStatusBarTranslucency() {
        return true;
    }

    @Override
    protected boolean toggleOverridePendingTransition() {
        return false;
    }

    @Override
    protected TransitionMode getOverridePendingTransitionMode() {
        return null;
    }

    public void findView(){
        itemv_update_password = findView(R.id.itemv_update_password);
        itemv_resetting_password = findView(R.id.itemv_resetting_password);
        mPresenter = new InitializePresenterImpl(mContext,this);
    }

    @Override
    public void onClick(View view) {
        switch (view.getId()){
            case R.id.itemv_update_password:
                readyGo(SetUpdateLoginPwdActivity.class);
                break;
            case R.id.itemv_resetting_password://重置密码
                zwgt_data = BaseRequestTool2.getFormatedDateString();
                JSONObject map = new JSONObject();
                try {
                    map.put("type","2");
                    map.put("phone", phone);
                    map.put("channel","0");
                } catch (JSONException e) {
                    e.printStackTrace();
                }

                JSONObject jsonParams = CommTool.getJSONParams(map, mConfigSP.getShareProf(TaskConstants.TASK_CONFIG), zwgt_data);
                mPresenter.loadingData(TaskConstants.TASK_SENDSMS, mContext.getString(R.string.root_url_test) + mContext.getString(R.string.api_index_test)
                        + TaskConstants.TASK_SENDSMS, Constants.EVENT_DATA, jsonParams, BaseRequestTool2.getHearder(mContext, TaskConstants.TASK_POST,
                        mContext.getString(R.string.api_index_test) + TaskConstants.TASK_SENDSMS, "", mConfigSP.getShareProf(TaskConstants.TASK_CONFIG), zwgt_data),false);
                Bundle bundle = new Bundle();
                bundle.putString("phone",phone);
                readyGo(ResettingPasswordActivity.class,bundle);
                break;
        }
    }

    @Override
    public <T> void initializeViews(String task_name, T data) {
        switch (task_name){
            case TaskConstants.TASK_SENDSMS:
                break;
        }
    }

    @Override
    public <T> void initializeError(String task_name, T data) {
    }
}
